import { Toast } from "vant";
import cTitle from "components/title";
export default {
  components: {
    cTitle
  },
  data() {
    return {
      storeId: null,
      storeDetail: {},
      workWeek: [
        //显示选中的日期数组
        {
          title: "周一",
          value: "1"
        },
        {
          title: "周二",
          value: "2"
        },
        {
          title: "周三",
          value: "3"
        },
        {
          title: "周四",
          value: "4"
        },
        {
          title: "周五",
          value: "5"
        },
        {
          title: "周六",
          value: "6"
        },
        {
          title: "周日",
          value: "7"
        }
      ]
    };
  },
  activated() {
    this.storeId = Number(this.$route.query.storeId);
    this.storeDetails();
  },
  methods: {
    storeDetails() {
      let json = {
        store_id: this.storeId
      };
      $http.post("plugin.coupon-store.frontend.store.storeDetail", json, "正在获取").then(
        response => {
          if (response.result == 1) {
            let res = response.data;
            let addressDetail = `${res.province}${res.city}${res.district}${res.street}${res.address}`,
              workWeek = res.work_week,
              workWeekData = this.workWeek,
              weekList = [];
            weekList = workWeekData.filter(item => workWeek.indexOf(item.value) > -1);
            let workTimeTitle = `${weekList[0].title}至${weekList[weekList.length - 1].title}`;
            this.storeDetail = response.data;
            this.addressDetail = addressDetail;
            this.workTime = workTimeTitle;
          } else {
            this.$dialog.alert({ message: response.msg });
          }
        },
        function(response) {
          console.log(response);
        }
      );
    }
  }
};
